<?php


namespace app\adminapi\dao\system;


use app\common\dao\BaseHotelDao;
use app\common\model\hotel\Hotel;
use app\common\model\system\SysMenu;

/**
 * @projectName src
 */
class SysMenuDao extends BaseHotelDao
{
    public static function add(array $params)
    {
        SysMenu::create([
            'parent_id' => $params['parent_id'] ?? 0,
            'menu_type' => $params['menu_type'],
            'menu_name' => $params['menu_name'] ?? '',
            'menu_icon' => $params['menu_icon'] ?? '',
            'path' => $params['path'] ?? '',
            'components' => $params['components'] ?? '',
            'permission' => $params['permission'] ?? '',
            'menu_order'=>$params['menu_order'] ?? 0,
            'menu_status'=>$params['menu_status'] ?? 1,
            'menu_show'=>$params['menu_show'] ?? 1,
            'is_target'=>$params['is_target'] ?? 0,
        ]);
    }

    public static function edit(array $params): bool
    {
        try {
            SysMenu::update($params);
            return true;
        } catch (\Exception $e) {
            self::setError($e->getMessage());
            return false;
        }
    }

    public static function delete(array $params)
    {
        SysMenu::destroy($params['id']);
    }

    public static function detail(array $params): array
    {
        return SysMenu::findOrEmpty($params['id'])->toArray();
    }

    public static function getAllData()
    {
        return SysMenu::order('id', 'desc')->select()->toArray();
    }
}